﻿using System;
using System.Windows.Forms;
using Distribution.Service;
using Entities;

namespace DistributionApplication.Controls
{
    public partial class MapSectionDropDown : UserControl
    {
        public MapSectionDropDown()
        {
            InitializeComponent();
        }

        public void LoadDropDowns()
        {
            EPolygon[] mapArray = LPolygon.GetAll(PolygonTypeEnum.Map).ToArray();
            //MobileUIHelper.FillDropdown(ddlMap, mapArray, "Name", "Id", "[Name]");
            MobileUIHelper.FillDropdown(ddlMap, mapArray, "[Map]");

            EPolygon[] sectionArray = LPolygon.GetAll(PolygonTypeEnum.Section).ToArray();
            //MobileUIHelper.FillDropdown(ddlSection, sectionArray, "Name", "Id", "[1 to 36]");
            MobileUIHelper.FillDropdown(ddlSection, sectionArray, "[Section]");
        }

        private void ddlMap_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlSection.Enabled = ddlMap.SelectedIndex > 0;
        }

        public EPolygon GetMap()
        {
            if (ddlMap.SelectedIndex > 0 && ddlMap.Items.Count > 0)
                return ddlMap.SelectedItem as EPolygon;
            
            return new EPolygon();
        }

        public EPolygon GetSection()
        {
            if (ddlSection.SelectedIndex > 0 && ddlSection.Items.Count > 0)
                return ddlSection.SelectedItem as EPolygon;

            return new EPolygon();
        }

        public void SetValues(EPole pole)
        {
            MobileUIHelper.SelectItem(ddlMap, pole.Map);
            MobileUIHelper.SelectItem(ddlSection, pole.Section);
        }

        public void Reset()
        {
            if (ddlMap.SelectedIndex > 0)
                ddlMap.SelectedIndex = 0;

            if (ddlSection.SelectedIndex > 0)
                ddlSection.SelectedIndex = 0;
        }
    }
}
